<?php

namespace app\health\model;

use think\Model;

/**
 * 站点轮播图模型
 */
class HealthWebsiteVideo extends Model
{
    // 表名
    protected $name = 'health_website_video';

    protected $append = [
        'duration_text'
    ];

    public function getDurationTextAttr($val, $data)
    {
        $duration = $data['duration'] ?? 0;
        $hours   = floor($duration / 3600);
        $minutes = floor(($duration - ($hours * 3600)) / 60);
        $seconds = $duration - ($hours * 3600) - ($minutes * 60);
        if ($hours > 0) {
            return str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($minutes, 2, '0', STR_PAD_LEFT) . ':' . str_pad($seconds, 2, '0', STR_PAD_LEFT);
        }
        return str_pad($minutes, 2, '0', STR_PAD_LEFT) . ':' . str_pad($seconds, 2, '0', STR_PAD_LEFT);
    }
}
